package com.xqboss.apps.service.hama;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xqboss.apps.domain.hama.HamaMixLog;
import com.xqboss.apps.mapper.hama.HamaMixLogMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xqboss.common.utils.DateUtils;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;


/**
 * <p>
 * 浑天池蛤蟆卡使用记录 服务实现类
 * </p>
 *
 * @author 木鱼
 * @since 2024-02-28
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class HamaMixLogService extends ServiceImpl<HamaMixLogMapper, HamaMixLog> {

    /**
     * 获取用户装备加油手环的记录列表
     *
     * @param page 分页
     * @param userId 用户id
     * @return 列表
     */
    public IPage<HamaMixLog> getHamaMixLog(Page<HamaMixLog> page,Long userId) {
        IPage<HamaMixLog> iPage = this.getBaseMapper().getHamaMixLog(page,userId);
        if (ObjUtil.isNotEmpty(iPage) && CollUtil.isNotEmpty(iPage.getRecords())) {
            iPage.getRecords().forEach(r->r.setHireHours(DateUtils.getEffectiveHour(r.getHireTime(),false)));
        }
        return iPage;
    }

    public static void main(String[] args) {
        System.out.println(DateUtils.getEffectiveHour(DateUtil.parse("2024-05-08 18:42:50"),false));
    }
}